package com.qianxiwitdoctor.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianxi.wit.pojo.TbDoctor;


import com.qianxi.wit.pojo.TbHospital;
import com.qianxi.wit.result.R;
import com.qianxiwitdoctor.mapper.TbHospitalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyh
 * @since 2021-01-09
 */
@RestController
@RequestMapping("/hospital")
public class TbHospitalController {

    @Autowired
    private TbHospitalMapper hospitalMapper;



    @PostMapping("/register/{PageSize}/{PageNum}")
    public R hlist(@PathVariable("PageSize")int PageSize,
                   @PathVariable("PageNum")int PageNum,
                   @RequestBody TbHospital hospital){
        try {
            Page<TbHospital> page = new Page<>(PageNum,PageSize);

            LambdaQueryWrapper<TbHospital> wrapper = new LambdaQueryWrapper<>();
            if(!"".equals(hospital.getHospitalName())){
                wrapper.like(TbHospital::getHospitalName,hospital.getHospitalName());
            }
            hospitalMapper.selectPage(page,wrapper);
            return R.ok().data("total",page.getTotal()).data("list",page.getRecords());
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }



}

